package vn.cuhanh.sdk;

import java.io.File;
import java.util.List;

import android.content.Context;

import com.android.zing.ZME_Base;
import com.android.zing.ZME_Config;
import com.android.zing.ZME_DialogListener;
import com.android.zing.ZME_Environment;
import com.android.zing.api.ZME_ASyncGraphAPI.RequestListener;
import com.android.zing.api.ZME_Me;
import com.android.zing.api.ZME_Photo;
import com.android.zing.api.ZME_User;
import com.android.zing.api.ZME_ZP;

public class ZingMeSDK {
	private final String appName = "mobile_cuhanh";
	private final String appId = "b7287694c9d24c04bda7bc2b4e16539e";
	private final String appSecret = "bf4ba6ec52974898ac50e635508d114c";
	
	private ZME_Config mConfig;
	private ZME_Base mZme;
    private ZME_Me mAsyncMe;
    private ZME_User mAsyncUser;
    private ZME_Photo mAsyncPhoto;
    private ZME_ZP mAsyncZingCredits = null;
	
	private final ZME_Environment env = ZME_Environment.PRODUCTION; 
	
	private static ZingMeSDK mInstance = null;
	
	public static ZingMeSDK getInstance() {
		if(mInstance == null) {
			mInstance = new ZingMeSDK();
		}
		return mInstance;
	}
	
	public ZingMeSDK() {
		mConfig = new ZME_Config(appName, appId, appSecret, ZME_Environment.PRODUCTION, true);
		mZme = new ZME_Base(mConfig);
		mAsyncMe = new ZME_Me(mZme);
        mAsyncUser = new ZME_User(mZme);
        mAsyncPhoto = new ZME_Photo(mZme);
	}
	
	public ZME_Base getZME_Base() {
		return mZme;
	}
	
	public ZME_Me getZME_Me() {
		return mAsyncMe;
	}
	
	public ZME_User getZME_User() {
		return mAsyncUser;
	}
	
	public ZME_Photo getZME_Photo() {
		return mAsyncPhoto;
	}
	
	public ZME_ZP getZME_ZP() {
		if(mAsyncZingCredits == null) mAsyncZingCredits = new ZME_ZP(mZme);
		return mAsyncZingCredits;
	}
	
	///////////////////// for authentication ///////////////
	public boolean isSessionValid(final Context ctx) {
		return mZme.isSessionValid(ctx);
	}
	
	public void authorize(final Context ctx, String state,
			final ZME_DialogListener listener) {
		mZme.authorize(ctx, state, listener);
	}
	
	public void logout(final Context ctx) {
		mZme.logout(ctx);
	}
	
	/////////////////// for me.Info /////////////////////
	public void getMeInfo(String fields, final RequestListener listener) {
		mAsyncMe.getInfo(fields, listener);
	}
	
	////////////////// for me.Friends //////////////////
	public void getMeFriends( final RequestListener listener ) {
		mAsyncMe.getFriends(listener);
	}
	
	/////////////// for me.isFanOf /////////////////////
	public void isFanOf( String fanpage, final RequestListener listener ) {
		mAsyncMe.isFanOf(fanpage, listener);
	}
	
	///////////////// for user.Info ///////////////////
	public void getUserInfo(List<Integer> uids, String fields,
			final RequestListener listener) {
		mAsyncUser.getInfo(uids, fields, listener);
	}
	
	//////////////// for photo.Upload ////////////////
	public void uploadPhoto(final File photoFile, String description, final RequestListener listener) {
		mAsyncPhoto.uploadPhoto(photoFile, description, listener);
	}
	
	public void uploadPhoto(String filePath, String description, final RequestListener listener) {
		mAsyncPhoto.uploadPhoto(filePath, description, listener);
	}
	
}
